package leetcode;


import com.alibaba.fastjson.JSON;

import java.util.Stack;

/**
 * 每日温度
 */
public class LeetCode739 {
    public int[] dailyTemperatures(int[] T) {
        Stack<Integer> stack = new Stack<>();
        int[] t = new int[T.length];
        for (int i = T.length - 1; i >= 0; i--) {
            while (!stack.isEmpty() && T[stack.peek()] <= T[i]) stack.pop();
            t[i] = stack.isEmpty() ? i - i : stack.peek() - i;
            stack.push(i);
        }
        return t;
    }

    public static void main(String[] args) {
        LeetCode739 leetCode739 = new LeetCode739();
        System.out.println(JSON.toJSONString(leetCode739.dailyTemperatures(new int[]{73, 74, 75, 71, 69, 72, 76, 73})));
    }
}